//
//  VisitorTableViewController.swift
//  weibo10
//
//  Created by 猎人 on 15/10/16.
//  Copyright © 2015年 hunter. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    //标记用户是否登录
    private var userLogon = UserAccountViewModel.sharedUserAccount.userLogon
    
    var visitorView: VisitorView?

    override func viewDidLoad() {

        userLogon ? super.loadView() : setupVisitorView()
        
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
//        print(visitorView)
    }
    ///设置访客视图
    private func setupVisitorView() {
        visitorView = VisitorView()
        
        view = visitorView
        
        //添加监听方法
        visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
   
    }
}

// MARK: -访客试图监听方法
extension VisitorTableViewController {
    func visitorViewDidRegister() {
        print("点击了注册按钮")
    }
    
    func visitorViewDidLogin() {
        
        let vc = OAuthViewController()
        let nv = UINavigationController(rootViewController: vc)
        
        presentViewController(nv, animated: true, completion: nil)
    }
}